﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Demo.SharePoint.Utilities;
using GM = Demo.SharePoint.Utilities.GoogleMaps;
using System.Runtime.InteropServices;

namespace Demo.SharePoint.LAYOUTS
{
    [Guid("3c2fc308-f3fb-45c6-856e-cc15051d96e3")]
    public partial class GoogleMaps : LayoutsPageBase
    {
        public TextBox TextBoxApiKey;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            TextBoxApiKey.Text = GM.GetApiKey(SPContext.Current.Web);
        }

        protected void BtnUpdateMapSettingsClick(object sender, EventArgs e)
        {
            //SPAudit audit = base.Web.Site.Audit;
            //audit.AuditFlags = this.GetAuditFlagsFromControls();
            //audit.Update();
            GM.SetApiKey(SPContext.Current.Web, TextBoxApiKey.Text);

            SPUtility.Redirect("settings.aspx", SPRedirectFlags.RelativeToLayoutsPage, this.Context);
        }

        protected void CancelButtonClick(object sender, EventArgs e)
        {
            string url = this.Context.Request.QueryString["CancelSource"];
            if (SPUtility.RedirectValidate(url, this.Context))
            {
                SPUtility.Redirect(url, SPRedirectFlags.Static, this.Context);
            }
            else
            {
                SPUtility.Redirect("settings.aspx", SPRedirectFlags.RelativeToLayoutsPage, this.Context);
            }
        }

        protected override bool RequireSiteAdministrator
        {
            get
            {
                return true;
            }
        }
    }
}
